<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
      <title>Using Hi.Disp.Drawing | HiAPI-C# 2025 </title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="title" content="Using Hi.Disp.Drawing | HiAPI-C# 2025 ">
      
      
      <link rel="icon" href="../../../../../img/HiAPI.favicon.ico">
      <link rel="stylesheet" href="../../../../../public/docfx.min.css">
      <link rel="stylesheet" href="../../../../../public/main.css">
      <meta name="docfx:navrel" content="../../../../../toc.html">
      <meta name="docfx:tocrel" content="../../../toc.html">
      
      <meta name="docfx:rel" content="../../../../../">
      
      
      
      <meta name="loc:inThisArticle" content="In this article">
      <meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
      <meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
      <meta name="loc:tocFilter" content="Filter by title">
      <meta name="loc:nextArticle" content="Next">
      <meta name="loc:prevArticle" content="Previous">
      <meta name="loc:themeLight" content="Light">
      <meta name="loc:themeDark" content="Dark">
      <meta name="loc:themeAuto" content="Auto">
      <meta name="loc:changeTheme" content="Change theme">
      <meta name="loc:copy" content="Copy">
      <meta name="loc:downloadPdf" content="Download PDF">

      <script type="module" src="./../../../../../public/docfx.min.js"></script>

      <script>
        const theme = localStorage.getItem('theme') || 'auto'
        document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
      </script>

  </head>

  <body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
    <header class="bg-body border-bottom">
      <nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
        <div class="container-xxl flex-nowrap">
          <a class="navbar-brand" href="../../../../../index.html">
            <img id="logo" class="svg" src="../../../../../img/HiAPI.logo.png" alt="">
            
          </a>
          <button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
            <i class="bi bi-three-dots"></i>
          </button>
          <div class="collapse navbar-collapse" id="navpanel">
            <div id="navbar">
              <form class="search" role="search" id="search">
                <i class="bi bi-search"></i>
                <input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
              </form>
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="container-xxl">
      <div class="toc-offcanvas">
        <div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body">
            <nav class="toc" id="toc"></nav>
          </div>
        </div>
      </div>

      <div class="content">
        <div class="actionbar">
          <button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
            <i class="bi bi-list"></i>
          </button>

          <nav id="breadcrumb"></nav>
        </div>

        <article data-uid="">
          <h1 id="using-hidispdrawing">Using Hi.Disp.Drawing</h1>

<p>The <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> class is the most fundamental and efficient rendering unit that allows you to draw points, lines, and surfaces within the <a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a>.</p>
<h2 id="understanding-drawing-structure">Understanding Drawing Structure</h2>
<p>Looking at the constructor <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html#Hi_Disp_Drawing__ctor_System_Double___Hi_Disp_Stamp_System_Int32_">Drawing(double[], Stamp, int)</a> helps explain its structure:</p>
<ul>
<li>The <code>double[]</code> array contains batch data for rendering, composed of one or more data groups of consistent length</li>
<li>Each data group's length is determined by the <a class="xref" href="../../../../../api/Hi.Disp.Stamp.html">Stamp</a> parameter</li>
<li>Each data group describes a single vertex</li>
</ul>
<h2 id="data-components">Data Components</h2>
<p>A data group can contain up to four types of information:</p>
<table>
<thead>
<tr>
<th>Information</th>
<th>Abbreviation</th>
<th>Description</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Vertex</strong></td>
<td>V</td>
<td>The position of the point (x, y, z)</td>
<td>3 doubles</td>
</tr>
<tr>
<td><strong>Normal</strong></td>
<td>N</td>
<td>The normal vector affecting light reflection (Nx, Ny, Nz)</td>
<td>3 doubles</td>
</tr>
<tr>
<td><strong>Color</strong></td>
<td>C</td>
<td>RGB color values ranging from 0 to 1</td>
<td>3 doubles</td>
</tr>
<tr>
<td><strong>Pick ID</strong></td>
<td>P</td>
<td>A single double value converted from an integer for selection operations</td>
<td>1 double</td>
</tr>
</tbody>
</table>
<p>The <a class="xref" href="../../../../../api/Hi.Disp.Stamp.html">Stamp</a> enumeration combines these abbreviations to create these possible stamps: <code>{V, NV, CV, CNV, PV, PNV, PCV, PCNV}</code>.</p>
<h3 id="important-notes">Important Notes:</h3>
<ul>
<li>The <strong>Vertex</strong> (V) is mandatory, which is why V appears in every Stamp option</li>
<li><strong>Normal</strong> vectors (N) are typically used for 3D graphics to create a sense of depth through lighting</li>
<li><strong>Color</strong> (C) uses three double values (R, G, B) in the range of 0 to 1</li>
<li><strong>Pick ID</strong> (P) is used for graphical selection operations</li>
</ul>
<h2 id="data-structure-example">Data Structure Example</h2>
<ul>
<li>If <a class="xref" href="../../../../../api/Hi.Disp.Stamp.html">Stamp</a> is <code>V</code>, each data group consists of 3 double values (x, y, z)</li>
<li>If <a class="xref" href="../../../../../api/Hi.Disp.Stamp.html">Stamp</a> is <code>PCV</code>, each data group consists of 1(P) + 3(C) + 3(V) = 7 double values</li>
</ul>
<h2 id="rendering-mode">Rendering Mode</h2>
<p>The <code>glmode</code> parameter is an OpenGL constant that specifies the drawing mode. You can search for &ldquo;OpenGL Primitives&rdquo; online to see illustrations of these modes.</p>
<h2 id="example-usage">Example Usage</h2>
<pre><code class="lang-csharp">// Creating a simple line strip with three vertices
double[] vertices = new double[] { 
    0, 0, 0,  // First point at origin
    1, 0, 0,  // Second point along X-axis
    0, 0, 1   // Third point along Z-axis
};

// Create drawing object using the vertices
var drawing = new Drawing(vertices, Stamp.V, (int)OpenGL.GL_LINE_STRIP);
</code></pre>
<p>This example creates three vertices with only position information (V), so each vertex has just xyz coordinates. The drawing mode is set to LineStrip.</p>
<p><img src="easydraw_lines.png" alt="Line Strip Drawing Example"></p>
<h2 id="performance-considerations">Performance Considerations</h2>
<div class="NOTE">
<h5>Note</h5>
<p>After a <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> object is created, its source data is stored in GPU memory. Regardless of the amount of data, the CPU processing load when calling <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html#Hi_Disp_IDisplayee_Display_Hi_Disp_Bind_">Display(Bind)</a> remains consistent. This means displaying 100 points with one <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> object is approximately 100 times faster than using 100 separate Drawing objects to display 100 individual points.</p>
</div>
<h2 id="composing-multiple-idisplayee-objects">Composing Multiple IDisplayee Objects</h2>
<p>A common pattern is to combine multiple <a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a> objects, including <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> objects:</p>
<pre><code class="lang-csharp">public class MyCompositeDisplayee : IDisplayee
{
    private readonly List&lt;IDisplayee&gt; _displayees = new List&lt;IDisplayee&gt;();
    
    public MyCompositeDisplayee()
    {
        // Create a grid drawing
        _displayees.Add(CreateGridDrawing());
        
        // Create an axes drawing
        _displayees.Add(CreateAxesDrawing());
        
        // Add other custom drawings
        _displayees.Add(CreateCustomDrawing());
    }
    
    private Drawing CreateGridDrawing()
    {
        // Code to create a grid
        double[] gridVertices = new double[/* grid data */];
        return new Drawing(gridVertices, Stamp.CV, (int)OpenGL.GL_LINES);
    }
    
    private Drawing CreateAxesDrawing()
    {
        // Create colored axes
        double[] axesData = new double[] {
            // Red X-axis (with color)
            1, 0, 0,  0, 0, 0,  // Red color, origin
            1, 0, 0,  1, 0, 0,  // Red color, x-axis end
            
            // Green Y-axis (with color)
            0, 1, 0,  0, 0, 0,  // Green color, origin
            0, 1, 0,  0, 1, 0,  // Green color, y-axis end
            
            // Blue Z-axis (with color)
            0, 0, 1,  0, 0, 0,  // Blue color, origin
            0, 0, 1,  0, 0, 1   // Blue color, z-axis end
        };
        
        return new Drawing(axesData, Stamp.CV, (int)OpenGL.GL_LINES);
    }
    
    public void Display(Bind bind)
    {
        // Render all contained displayees
        foreach (var displayee in _displayees)
        {
            displayee.Display(bind);
        }
    }
    
    public void ExpandToBox3d(Box3d box)
    {
        // Update bounding box based on all displayees
        foreach (var displayee in _displayees)
        {
            displayee.ExpandToBox3d(box);
        }
    }
}
</code></pre>
<h2 id="creating-common-shapes">Creating Common Shapes</h2>
<p>Here are some examples of creating common shapes using the <a class="xref" href="../../../../../api/Hi.Disp.Drawing.html">Drawing</a> class:</p>
<h3 id="creating-points">Creating Points</h3>
<pre><code class="lang-csharp">// Create an array of points
double[] pointData = new double[] {
    0, 0, 0,    // Point 1
    1, 1, 1,    // Point 2
    2, 0, 0,    // Point 3
    0, 2, 0     // Point 4
};

// Create a Drawing for points
var pointDrawing = new Drawing(pointData, Stamp.V, (int)OpenGL.GL_POINTS);
</code></pre>
<h3 id="creating-lines">Creating Lines</h3>
<pre><code class="lang-csharp">// Create line segments (pairs of vertices)
double[] lineData = new double[] {
    0, 0, 0,  1, 1, 0,   // Line 1: (0,0,0) to (1,1,0)
    2, 0, 0,  2, 2, 0    // Line 2: (2,0,0) to (2,2,0)
};

// Create a Drawing for lines
var lineDrawing = new Drawing(lineData, Stamp.V, (int)OpenGL.GL_LINES);
</code></pre>
<h3 id="creating-triangles">Creating Triangles</h3>
<pre><code class="lang-csharp">// Create triangles (triplets of vertices)
double[] triangleData = new double[] {
    // Triangle 1
    0, 0, 0,    // Vertex 1
    1, 0, 0,    // Vertex 2
    0, 1, 0     // Vertex 3
};

// Create a Drawing for triangles
var triangleDrawing = new Drawing(triangleData, Stamp.V, (int)OpenGL.GL_TRIANGLES);
</code></pre>
<h2 id="see-also">See Also</h2>
<ul>
<li><a class="xref" href="../../../../../api/Hi.Disp.DispEngine.html">DispEngine</a></li>
<li><a class="xref" href="../../../../../api/Hi.Disp.IDisplayee.html">IDisplayee</a></li>
<li><a class="xref" href="../../../../../api/Hi.Disp.DispList.html">DispList</a></li>
</ul>

</article>

        <div class="contribution d-print-none">
        </div>

        <div class="next-article d-print-none border-top" id="nextArticle"></div>

      </div>

      <div class="affix">
        <nav id="affix"></nav>
      </div>
    </main>

    <div class="container-xxl search-results" id="search-results"></div>

    <footer class="border-top text-secondary">
      <div class="container-xxl">
        <div class="flex-fill">
          <span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
        </div>
      </div>
    </footer>
  </body>
</html>
